<?php /*a:1:{s:51:"F:\wwwitem\fwdg\app\workerman\view\index\index.html";i:1628220746;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <title>测试</title>
</head>
<body>
测试下
</body>
<script type="text/javascript">
  console.log("nihao");
  var ws;
      //读取建筑消防设施系统状态
      var requestData = '{"type":"web","data":[1,2,3,4]}';

      function connect(){
        console.log("来了");
        ws = new WebSocket("ws://192.168.0.122:11000");
        // ws.binaryType = "arraybuffer";
        // 当socket连接打开时，输入用户名
            ws.onopen = onopen;
            // 当有消息时根据消息类型显示不同信息
            ws.onmessage = onmessage; 
            //关闭连接
            ws.onclose = function(){
              console.log("连接关闭，定时5秒后重连");
              setTimeout(function(){
                connect();
              },5000);
              
            }
            //出现错误
            ws.onerror = function(){
              console.log('出错了');
            }
      }

      function onopen(){
        console.log('连接成功');
        var data = requestData;
        console.log(data);
        ws.send(data);
      }

      function toSendMsg(){
        console.log('发送数据');

        var data = requestData;
        console.log(data);
        ws.send(data);
      }

      function onmessage(e){
        console.log('收到消息了');
        
      }

      connect();
</script>
</html>